import {h} from 'vue'
export const getDictData = (type,key,value,typeKey,columnsDist) => {
    //type 判断是否是字典
  //typeKey 1 判断value取label  2 判断key取title  3 判断id取name 4 判断id取nickname 5 判断id取username 6判断id取fee_name 7判断id取code 8判断id取car_number
  let label = ''
  let dict=[]
  if(type=='dictObj' || type=='attrs'){
   dict = columnsDist.dictObj?.data[key] ?? []
  }else{
   let dataObj = columnsDist[key]
   dict= dataObj ? dataObj.data : []
  }
  if(type == 'tags' || type == 'attrs'){
      if(!value){
        return '';
      }
      let str = []
      dict.map(i => {
        for(let index = 0 ; index < value.length ; index++){
              if (value[index] == i.id && type == 'tags') {
                str.push(h('a-tag',
                            {class: 'arco-tag arco-tag-size-medium arco-tag-checked',style:'background-color:'+i.color+';color:#fff;margin-top:3px'},
                            i.name
                          ))
                str.push(h('br'))
                // str.push(i)
              }
              if (value[index] == i.key && type == 'attrs') {
                str.push(h('a-tag',
                            {class: 'arco-tag arco-tag-size-medium arco-tag-checked',style:'background-color:#ccc;color:#fff;margin-top:3px'},
                            i.title
                          ))
                str.push(h('br'))
                // str.push(i)
              }
            }
      })
      return h('a-space',str)     
    }
  if(dict !== undefined && dict.length > 0){
        dict.map(i => {
          if(typeKey==1){
            if (value == i.value) {
              label = i.label
            }
          }else if(typeKey==2){
            if (value == i.key) {
              label = i.title
            }
          }else if(typeKey==3){
            if (value == i.id) {
              label = i.name
            }
          }else if(typeKey==4){
            if (value == i.id) {
              label = i.nickname
            }
          }else if(typeKey==5){
            if (value == i.id) {
              label = i.username
            }
          }else if(typeKey==6){
            if (value == i.id) {
              label = i.fee_name
            }
          }else if(typeKey==7){
            if (value == i.id) {
              label = i.code
            }
          }else if(typeKey==8){
            if (value == i.id) {
              label = i.car_number
            }
          }
        })
  }
  return label
  }  
//列表字段转换
export const DictData=(list,type,key)=>{
  let label=''
  list.map(i => {
    if(type==1){
      if(i.id==key){
        label=i.name
      }
    }else if(type==2){
      if(i.value==key){
        label=i.label
      }
    }
  })
return label
}